/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.棒球比赛;

import java.util.Collections;
import java.util.LinkedList;

public class Main {

    public int calPoints(String[] ops) {
        LinkedList<Integer> data = new LinkedList<>();
        for (String op : ops) {
            switch (op) {
                case "+":
                    int middle = data.pollLast();
                    int middle2 = data.peekLast();
                    data.addLast(middle);
                    data.addLast(middle + middle2);
                    break;
                case "D":
                    data.addLast(data.peekLast() * 2);
                    break;
                case "C":
                    data.pollLast();
                    break;
                default: {
                    data.addLast(Integer.valueOf(op));
                }
            }
        }
        int res = 0;
        for (Integer datum : data) {
            res += datum;
        }
        return res;
    }
}
